package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.*;
import com.sc.nft.entity.vo.*;
import com.sc.nft.enums.CouponsListStatusEnum;
import com.sc.nft.service.ActivityCouponsService;
import com.sc.nft.service.MallActivityService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author liGen
 * @version 1.0
 * @date 2023/12/6 3:50 下午
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/activity/coupons")
@Api(tags = "优惠券模块")
public class ActivityCouponsController {

    private final ActivityCouponsService activityCouponsService;
    private final MallActivityService mallActivityService;


    @ApiOperation(value = "优惠券列表", notes = "优惠券列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<ActivityCouponsDTO> activityCouponsPage(@RequestBody ActivityCouponsListVO activityCouponsListVO) {
        return PageResult.success(activityCouponsService.getAdminActivityCouponsDTOPage(activityCouponsListVO));
    }

    @ApiOperation(value = "添加优惠券", notes = "添加优惠券", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result add(@Valid @RequestBody EditActivityCouponsVO vo) {
        activityCouponsService.create(vo);
        return Result.success();
    }

    @ApiOperation(value = "编辑优惠券", notes = "编辑优惠券", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_VALUE)
    @Deprecated
    @SysMemberLogin
    public Result edit(@Valid @RequestBody EditActivityCouponsVO vo) {
        activityCouponsService.update(vo);
        return Result.success();
    }

    @ApiOperation(value = "优惠券活动上架", notes = "优惠券活动上架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/enable", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result enable(@Valid @RequestBody IdRequest idRequest) {
        activityCouponsService.enable(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "优惠券活动下架", notes = "优惠券活动下架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/disable", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result disable(@Valid @RequestBody IdRequest idRequest) {
        activityCouponsService.disable(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "修改优惠券活动排序 只传ID 以及 Sort", notes = "修改优惠券活动排序 只传ID 以及 status", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateSort", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateSort(@RequestBody EditActivityCouponsVO vo) {
        activityCouponsService.updateSort(vo.getId(),vo.getSort());
        return Result.success();
    }

    @ApiOperation(value = "优惠券详情", notes = "优惠券详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/details", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<ActivityCouponsDetailDTO> details(@RequestBody IdRequest idRequest) {
        ActivityCouponsDetailDTO activityCouponsDetailDTO = activityCouponsService.getActivityCouponsDetailDTOById(idRequest.getId());
        return Result.success(activityCouponsDetailDTO);
    }

    @ApiOperation(value = "优惠券下可用的商品列表", notes = "优惠券下可用的商品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/productList", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<ActivityCouponsProductDTO>> getActivityCouponsProductDTOPage(@Valid @RequestBody ActivityCouponsProductVO activityCouponsProductVO) {
        return Result.success(activityCouponsService.getActivityCouponsProductDTOList(activityCouponsProductVO));
    }

    @ApiOperation(value = "可添加到优惠券下的活动商品", notes = "可添加到优惠券下的活动商品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/canAddProductList", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<ActivityCouponsProductDTO> getActivityCouponsCanUseProductDTOPage(@Valid @RequestBody ActivityCouponsCanUseProductVO activityCouponsCanUseProductVO) {
        return PageResult.success(mallActivityService.getActivityCouponsCanUseProductDTOPage(new Page(activityCouponsCanUseProductVO.getPageNo(), activityCouponsCanUseProductVO.getPageSize()),activityCouponsCanUseProductVO.getProductName()));
    }

    @ApiOperation(value = "空投优惠券", notes = "空投优惠券", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/batchIssueCoupons", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result batchIssueCoupons(@Valid @RequestBody ActivityCouponsBatchIssueVO activityCouponsBatchIssueVO) {
        activityCouponsService.batchIssueCoupons(activityCouponsBatchIssueVO);
        return Result.success();
    }

    @ApiOperation(value = "空投选择优惠券", notes = "空投选择优惠券", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/batchIssuePage", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<ActivityBatchIssueCouponsDTO> batchIssuePage(@RequestBody ActivityCouponsListVO activityCouponsListVO) {
        return PageResult.success(activityCouponsService.batchIssuePage(activityCouponsListVO));
    }
}
